<!--
 * @Author: 张久冬
 * @Date: 2021-12-23 21:37:35
 * @
# Description:
-->
<template>
  <div class="nav-header">
    <el-icon @click="handFoldChange">
      <template v-if="isFold"><fold /></template>
      <template v-else><expand /></template>
    </el-icon>
    <div class="content">
      <JDBreadcrumb :breadcrumbs="breadcrumbs"></JDBreadcrumb>
      <UserInfo></UserInfo>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, computed, ref, ComputedRef } from 'vue'
import UserInfo from './user-info.vue'
import JDBreadcrumb from '@/base-ui/breadcrumb'
import type { IBreadcrumb } from '@/base-ui/breadcrumb'
import { pathMapBreadcrumbs } from '@/utils/map-menus'
import { useStore } from '@/store/index'
import { useRoute } from 'vue-router'

export default defineComponent({
  emits: ['foldChage'],
  components: { UserInfo, JDBreadcrumb },
  setup(props, { emit }) {
    const store = useStore()
    const isFold = ref(false)
    const handFoldChange = () => {
      isFold.value = !isFold.value
      emit('foldChage', isFold.value)
    }
    const breadcrumbs: ComputedRef<IBreadcrumb[]> = computed(() => {
      const userMenus = computed(() => store.state.login.userMenus)
      const currentPath = useRoute().path
      return pathMapBreadcrumbs(userMenus.value, currentPath)
    })

    return { handFoldChange, isFold, breadcrumbs }
  }
})
</script>

<style scoped lang="less">
.nav-header {
  display: flex;
  width: 100%;

  .fold-menu {
    font-size: 30px;
    cursor: pointer;
  }

  .content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 1;
    padding: 0 20px;
  }
}
</style>
